package hl.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ModelDriven;

import hl.pageModel.DataGrid;
import hl.pageModel.GroupCourse;
import hl.pageModel.Json;
import hl.service.GroupCourseService;


@Namespace("/")
@Action(value = "groupCourseAction")
public class GroupCourseAction extends BaseAction implements ModelDriven<GroupCourse> {

	GroupCourse groupCourse = new GroupCourse();

	private GroupCourseService groupCourseService;

	@Override
	public GroupCourse getModel() {
		return groupCourse;
	}

	public GroupCourseService getGroupCourseService() {
		return groupCourseService;
	}

	@Autowired
	public void setGroupCourseService(GroupCourseService groupCourseService) {
		this.groupCourseService = groupCourseService;
	}

	public void add() {
		Json j = new Json();
		try {
			groupCourseService.save(groupCourse);
			j.setSuccess(true);
			j.setMsg("保存成功");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void getDatagrid() {
		DataGrid d = groupCourseService.getDatagrid(groupCourse);
		super.writeJson(d);
	}

	public void edit() {
		Json j = new Json();
		try {
			groupCourseService.edit(groupCourse);
			j.setSuccess(true);
			j.setMsg("修改成功！");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void remove() {
		Json j = new Json();
		try {
			groupCourseService.remove(groupCourse);
			j.setSuccess(true);
			j.setMsg("删除成功！");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}
}
